﻿using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Services.Common;
using System;
using System.Collections.Generic;
using System.Text;

namespace Nop.Web.Services.Easemob
{
    public class EasemobHelper
    {
        private readonly IStaticCacheManager _cacheManager;
        private readonly EasemobManager _easemobManager;
        private readonly IGenericAttributeService _genericAttributeService;

        public EasemobHelper(EasemobManager easemobManager, IGenericAttributeService genericAttributeService, IStaticCacheManager cacheManager)
        {
            _easemobManager = easemobManager;
            _genericAttributeService = genericAttributeService;
            _cacheManager = cacheManager;
        }

        //public object GetUser(int customerId)
        //{
        //    var ucMemberId = _genericAttributeService.GetAttribute<long>(customerId,typeof(Customer), "NOP_UCMemberId");
        //    if (ucMemberId <1 ) {
        //        return null;
        //    }
        //    var user = _cacheManager.Get<EasemobUser>(easeUserName, () =>
        //    {
        //        EasemobUser _user = new EasemobUser();
        //        var json = _easemobManager.GetUser(easeUserName);
        //        if (string.IsNullOrEmpty(json))
        //        {
        //            var registerResult = _easemobManager.RegisterUser(easeUserName, easeUserName);
        //            var jObj = JsonConvert.DeserializeObject(registerResult) as JObject;
        //            if (jObj.ContainsKey("entities"))
        //            {
        //                _user.Uuid = (jObj["entities"] as JArray).First["uuid"].ToString();
        //            }

        //        }
        //        else
        //        {
        //            var jObj = JsonConvert.DeserializeObject(json) as JObject;
        //            if (jObj.ContainsKey("entities"))
        //            {
        //                _user.Uuid = (jObj["entities"] as JArray).First["uuid"].ToString();
        //            }
        //        }
        //        _user.Password = easeUserName;
        //        _user.UserName = easeUserName;
        //        return _user;
        //    });
        //}
    }
}
